package com.itheima.execption;

import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

// 注解配置异常处理器
// @Component
// @ControllerAdvice
public class ExceptionAdvice {

    @ExceptionHandler(NullPointerException.class)
    @ResponseBody
    public String doNullException(){
        return "NullPointerException...";
    }

    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public String doArithmeticException(){
        return "ArithmeticException...";
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public String doException(){
        return "Exception...";
    }

}

// 自定义，是controller出来后才被拦截，注解方式前端控制器中就开始拦截了！
